package oop.ex3.crosswords;

import java.util.Comparator;

/**
 * An implementation of Comparator,<br>
 * comparing values in lexicographic order.
 * 
 * @author tsachiho
 * @author kobi_atiya
 * 
 * @param <S>
 */
public class MyCrosswordGlossaryComparator<S> implements Comparator<String> {

    @Override
    public int compare(String o1, String o2) {
        if (eval(o1) == eval(o2)) return o1.compareTo(o2);

        return Integer.signum(eval(o2) - eval(o1));
    }

    /**
     * returning string's value - currently it's length,<br>
     * can be replaced with different values for each letter ("scrummble")
     * 
     * @param o1 - given term
     * @return - it's value
     */
    public static int eval(String o1) {
        return o1.length();
    }

}
